let users = [
    {id: "john", name: "John Smith", age: 20},
    {id: "ann", name: "Ann Smith", age: 24},
    {id: "pete", name: "Pete Peterson", age: 31},
];

let usersById = groupById(users);

alert(usersById['john']['id']);

alert(usersById['ann']['id']);

alert(usersById['pete']['id']);


function groupById(users) {
    return users.reduce(fn, {});
}


function fn(dict, item, index, array) {
    dict[item.id] = item;
    return dict;
}